﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Tong;
using Tong.TongJS_Prompt;

public partial class aspnet_admin_bock_News_CX_News_AddNew : System.Web.UI.Page
{
    /// <summary>
    /// 数据操作通用类 实例 TextData
    /// </summary> 
    public TongUse TextData = new TongUse();

    /// <summary>
    /// 系统安装绝对路径
    /// </summary>
    public string Abs_Path = TongUse.SysPath;
    /// <summary>
    /// 用户存放数据的临时表
    /// </summary>
    DataTable MyDt = new DataTable();

    JsPrompt JsAlert = new JsPrompt();

    /// <summary>
    /// 站点通用方法类
    /// </summary>
    public Tong.ThisSiteUse.SiteTong TextThisSite = new Tong.ThisSiteUse.SiteTong();

    public Tong.ThisSiteUse.CreateSiteHTMlFile CrtFile = new Tong.ThisSiteUse.CreateSiteHTMlFile();

    public string AdminShowId = "aa";  // 根据这个定位新闻栏目 //

    /// <summary>
    /// 初始化新闻分类ID
    /// </summary>
    public string CX_NEWS_Class_id = "";

    protected void Page_Load(object sender, EventArgs e)
    {
        // TextThisSite.selectMueuOption(0,TextThisSite.SqlOne("select CX_NEWS_Class_id from CX_News where CX_News_id=" + Request["AdminId"].ToString(),"CX_NEWS_Class_id"));
        if (Request["AdminId"] != null)
        {
            AdminShowId = TextThisSite.selectMueuOption(0, TextThisSite.SqlOne("select CX_NEWS_Class_id from CX_News where CX_News_id=" + Request["AdminId"].ToString(), "CX_NEWS_Class_id")); 
        }
        CX_NEWS_Pic.Attributes.Add("onclick", "showcc()");//添加图片显示事件
        SourceFrom.Attributes.Add("onchange", "document.getElementById('" + CX_NEWS_From.ClientID + "').value=this.value;");
        Authors.Attributes.Add("onchange", "document.getElementById('" + CX_NEWS_Creater.ClientID + "').value=this.value;");
        Keywordssss.Attributes.Add("onchange", "document.getElementById('" + Cx_keyWord_Name.ClientID + "').value=this.value;");
        Button2.Attributes.Add("onclick", "window.open('../../inc/UpFile.aspx?formname=aspnetForm&amp;editname=" + CX_NEWS_Pic_Url.ClientID.ToString() + "&amp;uppath=UpFile','','status=no,scrollbars=no,top=20,left=110,width=600,height=265')");
        if (!IsPostBack)
        {



            #region  病种关键字功能屏蔽 2007-10-11
            //帮关键字
            //DataTable TempTab = new DataTable();

            //TempTab = TextData.SqlataSet("select Cx_keyWord_id,Cx_keyWord_Name from [Cx_keyWord]").Tables[0];
            //string tempXtrst = Cx_keyWord_Name.ClientID + "=";
            //for (int i = 0; i < TempTab.Rows.Count; i++)
            //{
            //    tempXtrst += TempTab.Rows[i]["Cx_keyWord_Name"].ToString().Trim().Replace(";", "").Replace("\r", "").Replace("\n", "").Replace(" ", "").Replace("\"", "") + ",";
            //}
            //Labelalert.Text = JsAlert.Input_prompt(tempXtrst);
            //TempTab.Dispose();
            //TempTab.Clear();
            //Keywordssss.DataSource = TextData.SqlataSet("select Cx_keyWord_id,Cx_keyWord_Name from [Cx_keyWord]");
            //Keywordssss.DataTextField = "Cx_keyWord_Name";
            //Keywordssss.DataValueField = "Cx_keyWord_Name";
            //Keywordssss.DataBind();

            #endregion
            
     

            if (Request.Cookies["admin"]!=null)
            {
                CX_NEWS_Creater.Text = TextData.SqlataSet("select * from [Use] where uid='" + Request.Cookies["admin"].Value + "'").Tables[0].Rows[0]["UseName"].ToString();
            }


        }

        ///保存数据
        if (IsPostBack)
        {
            PageSave();
        }
        
    }


    //页面保存
    void PageSave()
    {

        if (CX_NEWS_Cont.Html.Trim() != "" && int.Parse(CX_NEWS_Sort.Text.Trim()) <= 99999 && CX_NEWS_Name.Text.Trim() != "")
        {
             CX_NEWS_Class_id = "";
            string ISpicNews = "0";//是不是显示为图片新闻
            string ISTOpNews = "0"; //是不是显示为头条新闻
            if (CX_NEWS_Top.Checked == true)
            {
                ISTOpNews = "1";
            }

            if (CX_NEWS_Pic.Checked == true)
            {
                ISpicNews = "1";
            }

            //看看是不是有选中 CX_NEWS_Class_id
            try
            {
                CX_NEWS_Class_id = Request.Form["CX_NEWS_Class_id"].Trim().Replace("'", "").Replace("\"", "");
            }
            catch
            {
                TextData.Err("程序不能完成你的添加新闻操作<br/>您没有选择所要添加新闻的分类");
            }

            string sql = "";
            sql = "insert into [CX_NEWS] (" +
             "  CX_NEWS_Title,CX_NEWS_Description,CX_NEWS_KeyWords,CX_NEWS_Name , CX_NEWS_Class_id ,CX_NEWS_Creater ,CX_NEWS_From ,CX_NEWS_Top , CX_NEWS_Pic , CX_NEWS_Pic_Url , CX_NEWS_Cont , CX_NEWS_Sort,Cx_keyWord_Name" +
                ") values(";
            sql = sql + "'" + CX_NEWS_Title.Text.Trim().Replace("'", "") + "','" + CX_NEWS_Description.Text.Trim().Replace("'", "") + "', '" + CX_NEWS_KeyWords.Text.Trim().Replace("'", "") + "','" + CX_NEWS_Name.Text.Trim() + "', " + CX_NEWS_Class_id + ", '" + CX_NEWS_Creater.Text.Trim() + "','" + CX_NEWS_From.Text.Trim() + "', '" + ISTOpNews + "','" + ISpicNews + "', '" + CX_NEWS_Pic_Url.Text.Trim() + "','" + CX_NEWS_Cont.Html.Trim().Replace("'", "") + "'," + CX_NEWS_Sort.Text.Trim() + ",'" +

                //Cx_keyWord_Name.Text.Trim().Replace("'", "") 病种关键字功能屏蔽 2007-10-11
                // +
               "'";
            //sql = sql + " CX_NEWS_Name = '" + CX_NEWS_Name.Text.Trim() + "',CX_NEWS_Class_id = " + CX_NEWS_Class_id.SelectedValue.Trim() + ",CX_NEWS_Creater = '" + CX_NEWS_Creater.Text.Trim() + "',CX_NEWS_From = '" + CX_NEWS_From.Text.Trim() + "',CX_NEWS_Top = '" + CX_NEWS_Top.Text.Trim() + "',CX_NEWS_Pic = '" + CX_NEWS_Pic.Text.Trim() + "',CX_NEWS_Pic_Url = '" + CX_NEWS_Pic_Url.Text.Trim() + "',CX_NEWS_Cont = '" + CX_NEWS_Cont.Html.Trim() + "',CX_NEWS_Sort= " + CX_NEWS_Sort.Text.Trim() + "";

            sql = sql + ")";
            TextData.SqlDataSave(sql);
            TextThisSite.AddNewCX_loginState(Request.Cookies["admin"].Value, "CX_News_AddNew.aspx", "添加新闻" + CX_NEWS_Name.Text + "");
            ;
            CX_NEWS_Name.Text = "";
            CX_NEWS_Cont.Html = "";
            try
            {
                string xxsstt = CrtFile.Create_News_POintNewsID(TextData.SqlataSet("select top 1 CX_NEWS_id  from [CX_NEWS] order by CX_NEWS_id desc").Tables[0].Rows[0][0].ToString()).Replace(Server.MapPath("/"), "/");
                tt.Text = "添加新闻 " + CX_NEWS_Name.Text + " 成功<br/>并以成功生成 <a href=\"" + xxsstt + "\" target=\"_blank\"> 点击查看" + xxsstt + "</a>";

            }
            catch
            {
                
            }
        }
        else
        {
            tt.Text = "新闻内容为空或其它内容为空";
        }
           
    }



}
